﻿// SteamDlg.cpp: 实现文件
//

#include "pch.h"
#include "Steam.h"
#include "afxdialogex.h"
#include "SteamDlg.h"
#include <string>
#include <vector>
#include "PipeFunc.h"
#include "PropertyData.h"

// CRoughDlg 对话框

IMPLEMENT_DYNAMIC(CRoughDlg, CDialogEx)

CRoughDlg::CRoughDlg(int nId, double rough, CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_ROUGH_DIALOG, pParent)
	, nSelect(nId)
	, rough(rough)
{

}

CRoughDlg::~CRoughDlg()
{
}

void CRoughDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_EDIT2, rough);
	DDX_CBIndex(pDX, IDC_PIPETYPE_COMBO, nSelect);
}


BEGIN_MESSAGE_MAP(CRoughDlg, CDialogEx)
	ON_CBN_SELCHANGE(IDC_PIPETYPE_COMBO, &CRoughDlg::OnCbnSelchangePipetypeCombo)
END_MESSAGE_MAP()


// CRoughDlg 消息处理程序


BOOL CRoughDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// TODO:  在此添加额外的初始化
	CComboBox* pPipeTypeCombo = (CComboBox*)GetDlgItem(IDC_PIPETYPE_COMBO);
	size_t nSize = sizeof PipeTypeForRough / sizeof PipeTypeForRough[0];
	for (size_t i = 0; i < nSize; i++)
	{
		pPipeTypeCombo->AddString(CString(PipeTypeForRough[i]));
	}

	UpdateData(0);
	if (CB_ERR != nSelect)
	{
		CString sRoughRange;
		sRoughRange.Format(_T("%g - %g"), RoughLow[nSelect], RoughUp[nSelect]);

		SetDlgItemText(IDC_ROUGHRANGE_EDIT, sRoughRange);
	}
	
	return TRUE;  // return TRUE unless you set the focus to a control
				  // 异常: OCX 属性页应返回 FALSE
}


void CRoughDlg::OnCbnSelchangePipetypeCombo()
{
	// TODO: 在此添加控件通知处理程序代码
	UpdateData();
	CString sRoughRange;
	if (fabs(RoughLow[nSelect] - RoughUp[nSelect]) < 1e-6)
	{
		sRoughRange.Format(_T("%g"), RoughLow[nSelect]);
	}
	else
	{
		sRoughRange.Format(_T("%g - %g"), RoughLow[nSelect], RoughUp[nSelect]);
	}
	

	SetDlgItemText(IDC_ROUGHRANGE_EDIT, sRoughRange);

	rough = 0.5  * (RoughLow[nSelect] + RoughUp[nSelect]);

	UpdateData(FALSE);
}


// CLocalDlg 对话框

IMPLEMENT_DYNAMIC(CLocalDlg, CDialogEx)

CLocalDlg::CLocalDlg(std::vector<int> _localIndexList, std::vector<int> _localNumList, std::vector<double> _localKlist, CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_LOCAL_DIALOG, pParent)
	, localIndexList(_localIndexList)
	, localNumList(_localNumList)
	, localKList(_localKlist)
	, kSum(0)
{

}

CLocalDlg::~CLocalDlg()
{
}

void CLocalDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_KSUM_EDIT, kSum);
}


BEGIN_MESSAGE_MAP(CLocalDlg, CDialogEx)
	ON_CBN_SELCHANGE(IDC_LOCALNAME_COMBO, &CLocalDlg::OnCbnSelchangeLocalnameCombo)
	ON_BN_CLICKED(IDC_ADD_BUTTON, &CLocalDlg::OnBnClickedAddButton)
	ON_NOTIFY(LVN_ITEMCHANGED, IDC_LOCAL_LIST, &CLocalDlg::OnLvnItemchangedLocalList)
	ON_BN_CLICKED(IDC_MODIFY_BUTTON, &CLocalDlg::OnBnClickedModifyButton)
	ON_BN_CLICKED(IDC_DELETE_BUTTON, &CLocalDlg::OnBnClickedDeleteButton)
END_MESSAGE_MAP()


// CLocalDlg 消息处理程序



BOOL CLocalDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// TODO:  在此添加额外的初始化
	size_t nSize = sizeof PipeFittingAndValve / sizeof PipeFittingAndValve[0];
	for (size_t i = 0; i < nSize; i++)
	{
		((CComboBox*)GetDlgItem(IDC_LOCALNAME_COMBO))->AddString(CString(PipeFittingAndValve[i]));
	}

	CListCtrl* pLocalList = (CListCtrl*)GetDlgItem(IDC_LOCAL_LIST);
	pLocalList->SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
	pLocalList->InsertColumn(0, _T("名称"), LVCFMT_LEFT, 120);
	pLocalList->InsertColumn(1, _T("阻力系数"), LVCFMT_LEFT, 80);
	pLocalList->InsertColumn(2, _T("数量"), LVCFMT_LEFT, 80);

	size_t nSize2 = localIndexList.size();
	for (size_t i = 0; i < nSize2; i++)
	{
		pLocalList->InsertItem(i, L"");
		CString sNum, sK;
		sNum.Format(_T("%d"), localNumList[i]);
		sK.Format(_T("%g"), localKList[i]);

		pLocalList->SetItemText(i, 0, CString(PipeFittingAndValve[localIndexList[i]]));
		pLocalList->SetItemText(i, 1, sNum);
		pLocalList->SetItemText(i, 2, sK);

		kSum += localNumList[i] * localKList[i];
	}
	
	UpdateData(FALSE);

	return TRUE;  // return TRUE unless you set the focus to a control
				  // 异常: OCX 属性页应返回 FALSE
}



void CLocalDlg::OnCbnSelchangeLocalnameCombo()
{
	// TODO: 在此添加控件通知处理程序代码
	int nNameSelect = ((CComboBox*)GetDlgItem(IDC_LOCALNAME_COMBO))->GetCurSel();
	CString sSuggestKBuf;
	sSuggestKBuf.Format(_T("%g"), LocalResistanceCoef[nNameSelect]);
	SetDlgItemText(IDC_KSUGGEST_EDIT, sSuggestKBuf);
	SetDlgItemText(IDC_K_EDIT, sSuggestKBuf);
}


void CLocalDlg::OnLvnItemchangedLocalList(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
	// TODO: 在此添加控件通知处理程序代码
	CListCtrl* pLocalList = (CListCtrl*)GetDlgItem(IDC_LOCAL_LIST);
	POSITION pos = pLocalList->GetFirstSelectedItemPosition();
	
	if (pos == NULL)
	{
		return;
	}
	else
	{
		while (pos)
		{
			nSelect = pLocalList->GetNextSelectedItem(pos);
		}
	}

	int nId = localIndexList[nSelect];

	((CComboBox*)GetDlgItem(IDC_LOCALNAME_COMBO))->SetCurSel(nId);

	CString sSuggestKBuf;
	sSuggestKBuf.Format(_T("%g"), LocalResistanceCoef[nId]);
	SetDlgItemText(IDC_KSUGGEST_EDIT, sSuggestKBuf);

	CString sKBuf;
	sKBuf.Format(_T("%g"), localKList[nSelect]);
	SetDlgItemText(IDC_K_EDIT, sKBuf);

	CString sNumBuf;
	sNumBuf.Format(_T("%d"), localNumList[nSelect]);
	SetDlgItemText(IDC_NUM_EDIT, sNumBuf);

	*pResult = 0;
}

void CLocalDlg::OnBnClickedAddButton()
{
	// TODO: 在此添加控件通知处理程序代码
	CComboBox* pLocalNameCombo = (CComboBox*)GetDlgItem(IDC_LOCALNAME_COMBO);
	localIndexList.push_back(pLocalNameCombo->GetCurSel());
	CString name;
	pLocalNameCombo->GetLBText(pLocalNameCombo->GetCurSel(), name);

	CString sKBuf;
	GetDlgItemText(IDC_K_EDIT, sKBuf);
	localKList.push_back(_ttof(sKBuf));
	
	CString sNumBuf;
	GetDlgItemText(IDC_NUM_EDIT, sNumBuf);
	localNumList.push_back(_ttoi(sNumBuf));
	
	CListCtrl* pLocalList = (CListCtrl*)GetDlgItem(IDC_LOCAL_LIST);
	int i = pLocalList->GetItemCount();
	pLocalList->InsertItem(i, L"");
	pLocalList->SetItemText(i, 0, name);
	pLocalList->SetItemText(i, 1, sKBuf);
	pLocalList->SetItemText(i, 2, sNumBuf);

	kSum = 0;
	size_t nSize = localNumList.size();
	for (size_t i = 0; i < nSize; i++)
	{
		kSum += localNumList[i] * localKList[i];
	}

	UpdateData(FALSE);
}

void CLocalDlg::OnBnClickedModifyButton()
{
	// TODO: 在此添加控件通知处理程序代码
	if (nSelect == -1)
	{
		return;
	}

	//UpdateData();
	CComboBox* pLocalNameCombo = (CComboBox*)GetDlgItem(IDC_LOCALNAME_COMBO);
	localIndexList[nSelect] = pLocalNameCombo->GetCurSel();
	CString name;
	pLocalNameCombo->GetLBText(pLocalNameCombo->GetCurSel(), name);

	CString sKBuf;
	GetDlgItemText(IDC_K_EDIT, sKBuf);
	localKList[nSelect] = _ttof(sKBuf);

	CString sNumBuf;
	GetDlgItemText(IDC_NUM_EDIT, sNumBuf);
	localNumList[nSelect] = _ttoi(sNumBuf);

	CListCtrl* pLocalList = (CListCtrl*)GetDlgItem(IDC_LOCAL_LIST);
	//pLocalList->InsertItem(nSelect, L"");
	pLocalList->SetItemText(nSelect, 0, name);
	pLocalList->SetItemText(nSelect, 1, sKBuf);
	pLocalList->SetItemText(nSelect, 2, sNumBuf);

	kSum = 0;
	size_t nSize = localNumList.size();
	for (size_t i = 0; i < nSize; i++)
	{
		kSum += localNumList[i] * localKList[i];
	}

	UpdateData(FALSE);
}


void CLocalDlg::OnBnClickedDeleteButton()
{
	// TODO: 在此添加控件通知处理程序代码
	localIndexList.erase(localIndexList.begin() + nSelect);
	localNumList.erase(localNumList.begin() + nSelect);
	localKList.erase(localKList.begin() + nSelect);

	((CListCtrl*)GetDlgItem(IDC_LOCAL_LIST))->DeleteItem(nSelect);

	kSum = 0;
	size_t nSize = localNumList.size();
	for (size_t i = 0; i < nSize; i++)
	{
		kSum += localNumList[i] * localKList[i];
	}

	UpdateData(FALSE);
}


// CInsulDlg 对话框

IMPLEMENT_DYNAMIC(CInsulDlg, CDialogEx)

CInsulDlg::CInsulDlg(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_INSUL_DIALOG, pParent)
{

}

CInsulDlg::~CInsulDlg()
{
}

void CInsulDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CInsulDlg, CDialogEx)
	ON_NOTIFY(LVN_ITEMCHANGED, IDC_INSUL_LIST, &CInsulDlg::OnLvnItemchangedInsulList)
END_MESSAGE_MAP()


// CInsulDlg 消息处理程序

BOOL CInsulDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// TODO:  在此添加额外的初始化
	CListCtrl* pInsulList = (CListCtrl*)GetDlgItem(IDC_INSUL_LIST);
	pInsulList->SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
	pInsulList->InsertColumn(0, _T("绝热材料"), LVCFMT_LEFT, 120);
	pInsulList->InsertColumn(2, _T("型式"), LVCFMT_LEFT, 60);
	pInsulList->InsertColumn(2, _T("使用密度 kg/m3"), LVCFMT_LEFT, 100);
	pInsulList->InsertColumn(3, _T("最高使用温度 C"), LVCFMT_LEFT, 100);
	pInsulList->InsertColumn(4, _T("推荐使用温度范围 C"), LVCFMT_LEFT, 120);
	pInsulList->InsertColumn(5, _T("常用导热系数W/(m.K)"), LVCFMT_LEFT, 140);

	Insul* insul = (Insul*)malloc(sizeof(Insul) * 62);

	const char* datFile = "dat/Insulation.dat";

	int row = getPropertyData(datFile, insul, 0, 61);

	char preNameBuf[40] = "\0", preRemarkBuf[20] = "\0";
	unsigned int preDensity_min = 100000, preDensity_max = 100000;

	if (insul != NULL)
	{
		for (size_t i = 0, k = 0; i < row; i++)
		{
			if (strcmp(preNameBuf, (insul + i)->name) == 0 && strcmp(preRemarkBuf, (insul + i)->remark) == 0 &&
				preDensity_max == (insul + i)->density_max && preDensity_min == (insul + i)->density_min)
			{
				continue;
			}

			strcpy_s(preNameBuf, sizeof preNameBuf, (insul + i)->name);
			strcpy_s(preRemarkBuf, sizeof preRemarkBuf, (insul + i)->remark);
			preDensity_max = (insul + i)->density_max;
			preDensity_min = (insul + i)->density_min;

			pInsulList->InsertItem(k, L"");
			pInsulList->SetItemText(k, 0, CString((insul + i)->name));
			pInsulList->SetItemText(k, 1, CString((insul + i)->remark));


			CString strDensity, strAllowTemperatureMax, strReTemperatureMax, strTc0;
			if ((insul + i)->density_min == (insul + i)->density_max)
			{
				strDensity.Format(_T("%u"), (insul + i)->density_min);
			}
			else if ((insul + i)->density_max == 99999)
			{
				strDensity.Format(_T("≥%u"), (insul + i)->density_min);
			}
			else if ((insul + i)->density_min == 0)
			{
				strDensity.Format(_T("≤%u"), (insul + i)->density_max);
			}
			else
			{
				strDensity.Format(_T("%u-%u"), (insul + i)->density_min, (insul + i)->density_max);
			}
			pInsulList->SetItemText(k, 2, strDensity);

			strAllowTemperatureMax.Format(_T("%d"), (insul + i)->allowTemperature_max);
			pInsulList->SetItemText(k, 3, strAllowTemperatureMax);

			strReTemperatureMax.Format(_T("≤%d"), (insul + i)->reTemperature_max);
			pInsulList->SetItemText(k, 4, strReTemperatureMax);

			strTc0.Format(_T("%g"), (insul + i)->tc0);
			pInsulList->SetItemText(k, 5, strTc0);

			m_idList.push_back(i);

			k++;
		}
	}

	return TRUE;  // return TRUE unless you set the focus to a control
				  // 异常: OCX 属性页应返回 FALSE
}


void CInsulDlg::OnLvnItemchangedInsulList(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
	// TODO: 在此添加控件通知处理程序代码

	int nItemSelected;
	CListCtrl* pInsulList = (CListCtrl*)GetDlgItem(IDC_INSUL_LIST);
	POSITION pos = pInsulList->GetFirstSelectedItemPosition();
	if (pos == NULL)
	{
		return;
	}
	else
	{
		while (pos)
		{
			nItemSelected = pInsulList->GetNextSelectedItem(pos);
		}
	}

	Insul* insul = (Insul*)malloc(sizeof(Insul));

	const char* datFile = "dat/Insulation.dat";
	nId = m_idList[nItemSelected];
	int row = getPropertyData(datFile, insul, nId, 1);
	if (insul != NULL)
	{
		//currentInsulName.Format(_T("%s %s"), insul->name, insul->remark);
		sName = CString(insul->name) + _T(" [") + CString(insul->remark) + _T("]");
	}

	*pResult = 0;
}


// CBlacknessDlg 对话框

IMPLEMENT_DYNAMIC(CBlacknessDlg, CDialogEx)

CBlacknessDlg::CBlacknessDlg(int nId, double blackness, CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_BLACKNESS_DIALOG, pParent)
	, nSelect(nId)
	, blackness(blackness)
{

}

CBlacknessDlg::~CBlacknessDlg()
{
}

void CBlacknessDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_CBIndex(pDX, IDC_SHELL_COMBO, nSelect);
	DDX_Text(pDX, IDC_BLACKNESS_EDIT, blackness);
}


BEGIN_MESSAGE_MAP(CBlacknessDlg, CDialogEx)
	ON_CBN_SELCHANGE(IDC_SHELL_COMBO, &CBlacknessDlg::OnCbnSelchangeShellCombo)
END_MESSAGE_MAP()


// CBlacknessDlg 消息处理程序

BOOL CBlacknessDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// TODO:  在此添加额外的初始化
	CComboBox* pShellCombo = (CComboBox*)GetDlgItem(IDC_SHELL_COMBO);
	size_t nSize = sizeof Shell / sizeof Shell[0];
	for (size_t i = 0; i < nSize; i++)
	{
		pShellCombo->AddString(CString(Shell[i]));
	}

	UpdateData(0);
	if (CB_ERR != nSelect)
	{
		CString sBlacknessRange;
		sBlacknessRange.Format(_T("%g - %g"), ShellBlacknessLow[nSelect], ShellBlacknessUp[nSelect]);

		SetDlgItemText(IDC_BLACKNESSRANGE_EDIT, sBlacknessRange);
	}

	return TRUE;  // return TRUE unless you set the focus to a control
				  // 异常: OCX 属性页应返回 FALSE
}


void CBlacknessDlg::OnCbnSelchangeShellCombo()
{
	// TODO: 在此添加控件通知处理程序代码
	UpdateData();
	CString sBlacknessRange;
	if (fabs(ShellBlacknessLow[nSelect]- ShellBlacknessUp[nSelect]) < 1e-6)
	{
		sBlacknessRange.Format(_T("%g"), ShellBlacknessLow[nSelect]);
	}
	else
	{
		sBlacknessRange.Format(_T("%g - %g"), ShellBlacknessLow[nSelect], ShellBlacknessUp[nSelect]);
	}
	
	SetDlgItemText(IDC_BLACKNESSRANGE_EDIT, sBlacknessRange);

	blackness = 0.5  * (ShellBlacknessLow[nSelect] + ShellBlacknessUp[nSelect]);

	UpdateData(FALSE);
}


// CEnvironmentDlg 对话框

IMPLEMENT_DYNAMIC(CEnvironmentDlg, CDialogEx)

CEnvironmentDlg::CEnvironmentDlg(CString sCity, int nPlace, CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_ENVIRONMENT_DIALOG, pParent)
	, sCity(sCity)
	, nPlace(nPlace)
{

}

CEnvironmentDlg::~CEnvironmentDlg()
{
}

void CEnvironmentDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Radio(pDX, IDC_PLACE1_RADIO, nPlace);
}


BEGIN_MESSAGE_MAP(CEnvironmentDlg, CDialogEx)
	ON_CBN_SELCHANGE(IDC_PROVINCE_COMBO, &CEnvironmentDlg::OnCbnSelchangeProvinceCombo)
	ON_BN_CLICKED(IDOK, &CEnvironmentDlg::OnBnClickedOk)
END_MESSAGE_MAP()


// CEnvironmentDlg 消息处理程序


BOOL CEnvironmentDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// TODO:  在此添加额外的初始化
	CComboBox* pProvinceCombo = (CComboBox*)GetDlgItem(IDC_PROVINCE_COMBO);
	
	CTYW* ctyw = (CTYW*)malloc(sizeof(CTYW) * 80);

	int row = getPropertyData("dat/ctyw.dat", ctyw, 0, 0);
	std::vector<std::string> provinceList;
	int index = -1;
	if (ctyw != NULL)
	{
		for (size_t i = 0, k = 0; i < row; i++)
		{
			if (std::find(std::begin(provinceList), std::end(provinceList), (ctyw + i)->province) == std::end(provinceList))
			{
				provinceList.push_back((ctyw + i)->province);

				k++;
			}
			if (sCity == CString((ctyw + i)->city))
			{
				index = k;
			}
		}
		for (std::string province : provinceList)
		{
			pProvinceCombo->AddString(CString(province.c_str()));
		}

		if (index == -1)
		{
			pProvinceCombo->SetCurSel(14);
		}
		else
		{
			pProvinceCombo->SetCurSel(index - 1);
		}

		OnCbnSelchangeProvinceCombo();
	}
	//UpdateData(FALSE);
	return TRUE;  // return TRUE unless you set the focus to a control
				  // 异常: OCX 属性页应返回 FALSE
}


void CEnvironmentDlg::OnCbnSelchangeProvinceCombo()
{
	// TODO: 在此添加控件通知处理程序代码
	CComboBox* pProvinceCombo = (CComboBox*)GetDlgItem(IDC_PROVINCE_COMBO);
	CComboBox* pCityCombo = (CComboBox*)GetDlgItem(IDC_CITY_COMBO);
	pCityCombo->ResetContent();
	int currentProvinceIndex = pProvinceCombo->GetCurSel();
	CTYW* ctyw = (CTYW*)malloc(sizeof(CTYW) * 80);
	int row = getPropertyData("dat/ctyw.dat", ctyw, 0, 0);
	if (ctyw != NULL)
	{
		for (size_t i = 0; i < row; i++)
		{
			double n = (ctyw + i)->id - currentProvinceIndex;
			if (n > 1 && n < 2)
			{
				pCityCombo->AddString(CString((ctyw + i)->city));
			}
		}

		if (pCityCombo->SelectString(0, sCity) == CB_ERR)
		{
			pCityCombo->SetCurSel(0);
		}
	}
}


void CEnvironmentDlg::OnBnClickedOk()
{
	// TODO: 在此添加控件通知处理程序代码
	CComboBox* pCityCombo = (CComboBox*)GetDlgItem(IDC_CITY_COMBO);
	pCityCombo->GetLBText(pCityCombo->GetCurSel(), sCity);
	CDialogEx::OnOK();
}


// CPmpDlg 对话框

IMPLEMENT_DYNAMIC(CPmpDlg, CDialogEx)

CPmpDlg::CPmpDlg(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_PMP_DIALOG, pParent)
{

}

CPmpDlg::~CPmpDlg()
{
}

void CPmpDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CPmpDlg, CDialogEx)
	ON_CBN_SELCHANGE(IDC_MC_COMBO, &CPmpDlg::OnCbnSelchangeMcCombo)
	ON_CBN_SELCHANGE(IDC_PC_COMBO, &CPmpDlg::OnCbnSelchangePcCombo)
	ON_BN_CLICKED(IDOK, &CPmpDlg::OnBnClickedOk)
END_MESSAGE_MAP()


// CPmpDlg 消息处理程序


BOOL CPmpDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// TODO:  在此添加额外的初始化
	CComboBox* pMcCombo = (CComboBox*)GetDlgItem(IDC_MC_COMBO);
	PipeMaterialProperties* pmp = (PipeMaterialProperties*)malloc(sizeof(PipeMaterialProperties) * 260);
	int row = getPropertyData("dat/material.dat", pmp, 0, 0);
	std::vector<std::string> mClassList;
	if (pmp != NULL)
	{
		for (size_t i = 0; i < row; i++)
		{
			if (std::find(std::begin(mClassList), std::end(mClassList), (pmp + i)->MClass) == std::end(mClassList))
			{
				//m_cbMClass.AddString(CString((pmp + i)->MClass));
				mClassList.push_back((pmp + i)->MClass);
			}
		}

		for (std::string strItem : mClassList)
		{
			pMcCombo->AddString(CString(strItem.c_str()));
		}
		pMcCombo->SetCurSel(1);
	}
	CListCtrl* pPmpList = (CListCtrl*)GetDlgItem(IDC_PMP_LIST);
	pPmpList->SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
	pPmpList->InsertColumn(0, _T("标准"), LVCFMT_LEFT, 60);
	pPmpList->InsertColumn(1, _T("牌号等级"), LVCFMT_LEFT, 100);
	pPmpList->InsertColumn(2, _T("尺寸范围 mm"), LVCFMT_LEFT, 80);
	pPmpList->InsertColumn(3, _T("最低使用温度 C"), LVCFMT_LEFT, 100);
	pPmpList->InsertColumn(4, _T("最高使用温度 C"), LVCFMT_LEFT, 100);

	OnCbnSelchangeMcCombo();

	return TRUE;  // return TRUE unless you set the focus to a control
				  // 异常: OCX 属性页应返回 FALSE
}


void CPmpDlg::OnCbnSelchangeMcCombo()
{
	// TODO: 在此添加控件通知处理程序代码
	CComboBox* pMcCombo = (CComboBox*)GetDlgItem(IDC_MC_COMBO);
	CComboBox* pPcCombo = (CComboBox*)GetDlgItem(IDC_PC_COMBO);

	pPcCombo->ResetContent();
	int currentMClassIndex = pMcCombo->GetCurSel();
	CString strMClass;
	pMcCombo->GetLBText(currentMClassIndex, strMClass);

	PipeMaterialProperties* pmp = (PipeMaterialProperties*)malloc(sizeof(PipeMaterialProperties) * 260);
	int row = getPropertyData("dat/material.dat", pmp, 0, 0);
	std::vector<std::string> mPipeNameList;
	if (pmp != NULL)
	{
		for (size_t i = 0; i < row; i++)
		{
			if (CString((pmp + i)->MClass) == strMClass)
			{
				if (std::find(std::begin(mPipeNameList), std::end(mPipeNameList), (pmp + i)->pipeName) == std::end(mPipeNameList))
				{
					//m_cbMClass.AddString(CString((pmp + i)->MClass));
					mPipeNameList.push_back((pmp + i)->pipeName);
				}
			}
		}

		for (std::string strItem : mPipeNameList)
		{
			pPcCombo->AddString(CString(strItem.c_str()));
		}
		pPcCombo->SetCurSel(0);
		OnCbnSelchangePcCombo();
	}
}


void CPmpDlg::OnCbnSelchangePcCombo()
{
	// TODO: 在此添加控件通知处理程序代码
	CComboBox* pMcCombo = (CComboBox*)GetDlgItem(IDC_MC_COMBO);
	CComboBox* pPcCombo = (CComboBox*)GetDlgItem(IDC_PC_COMBO);
	CListCtrl* pPmpList = (CListCtrl*)GetDlgItem(IDC_PMP_LIST);
	pPmpList->DeleteAllItems();
	m_nPmpIdList.clear();
	CString strMClass, strPipeName;
	int currentMClassIndex = pMcCombo->GetCurSel();
	pMcCombo->GetLBText(currentMClassIndex, strMClass);

	int currentPipeNameIndex = pPcCombo->GetCurSel();
	pPcCombo->GetLBText(currentPipeNameIndex, strPipeName);

	PipeMaterialProperties* pmp = (PipeMaterialProperties*)malloc(sizeof(PipeMaterialProperties) * 260);
	int row = getPropertyData("dat/material.dat", pmp, 0, 0);
	std::vector<std::string> mPipeNameList;
	if (pmp != NULL)
	{
		int nItem = 0;
		for (size_t i = 0; i < row; i++)
		{
			if (CString((pmp + i)->MClass) == strMClass && CString((pmp + i)->pipeName) == strPipeName)
			{
				CString strThkRange, strTmax;
				//strIndex.Format(_T("%d"), i);

				if ((pmp + i)->thickness_min == 0)
				{
					if ((pmp + i)->thickness_max == 99999)
					{
						strThkRange = _T("全部");
					}
					else
					{
						strThkRange.Format(_T("≤%u"), (pmp + i)->thickness_max);
					}
				}
				else
				{
					if ((pmp + i)->thickness_max == 99999)
					{
						strThkRange.Format(_T(">%u"), (pmp + i)->thickness_min);
					}
					else
					{
						strThkRange.Format(_T(">%u～%u"), (pmp + i)->thickness_min, (pmp + i)->thickness_max);
					}
				}

				strTmax.Format(_T("%u"), (pmp + i)->temperature_max);
				pPmpList->InsertItem(nItem, L"");
				pPmpList->SetItemText(nItem, 0, CString((pmp + i)->pipeCode));
				pPmpList->SetItemText(nItem, 1, CString((pmp + i)->MCode));
				pPmpList->SetItemText(nItem, 2, strThkRange);
				pPmpList->SetItemText(nItem, 3, CString((pmp + i)->temperature_min));
				pPmpList->SetItemText(nItem, 4, strTmax);
				nItem++;

				m_nPmpIdList.push_back((pmp + i)->id);

			}
		}
	}
}


void CPmpDlg::OnBnClickedOk()
{
	// TODO: 在此添加控件通知处理程序代码
	CListCtrl* pPmpList = (CListCtrl*)GetDlgItem(IDC_PMP_LIST);
	int currentPipeListSelIndex;
	POSITION pos = pPmpList->GetFirstSelectedItemPosition();
	if (pos == NULL)
	{
		return;
	}
	else
	{
		while (pos)
		{
			currentPipeListSelIndex = pPmpList->GetNextSelectedItem(pos);
		}
	}

	nId = m_nPmpIdList[currentPipeListSelIndex];
	CDialogEx::OnOK();
}


// CWeldingDlg 对话框

IMPLEMENT_DYNAMIC(CWeldingDlg, CDialogEx)

CWeldingDlg::CWeldingDlg(int nWelding, double rtPercent, CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_WELDING_DIALOG, pParent)
	, nWeldingType(nWelding)
	, RTPercent(rtPercent)
{

}

CWeldingDlg::~CWeldingDlg()
{
}

void CWeldingDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Radio(pDX, IDC_1_RADIO, nWeldingType);
	DDX_Text(pDX, IDC_RTPERCENT_EDIT, RTPercent);
}


BEGIN_MESSAGE_MAP(CWeldingDlg, CDialogEx)
END_MESSAGE_MAP()


// CWeldingDlg 消息处理程序




